package com.literature.threeGroup.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.literature.threeGroup.mapper.*;
import com.literature.threeGroup.pojo.*;
import com.literature.threeGroup.service.CoversService;
import com.literature.threeGroup.util.IdWorker;
import com.literature.threeGroup.util.PageResult;
import com.literature.threeGroup.util.SystemIDUtil;
import com.literature.threeGroup.vo.CoverVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author VULCAN
 * @create 2020-01-07 14:30
 * @desc
 **/
@Service
public class CoversServiceImpl implements CoversService {

    @Autowired
    private AgencyCompanyMapper agencyCompanyMapper;
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private CoverMapper coversMapper;
    @Autowired
    private CoverVoMapper coverVoMapper;
    @Autowired
    private CoverOrderMapper coverOrderMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OrderMapper orderMapper;
//    @Autowired
//    private OrdersMapper ordersMapper;
    @Autowired
    private PurchaseMapper purchaseMapper;
    @Autowired
    private CoverSnapshotMapper coverSnapshotMapper;
    /**
     * @name  代理公司列表
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public List<AgencyCompany> AgencyCompanyFindlist() {
        return agencyCompanyMapper.AgencyCompanyFindlist();
    }
    /**
     * @name  新增代理公司
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public void AgencyCompanyadd(AgencyCompany agencyCompany) {
        agencyCompany.setId(idWorker.nextId()+"");
        agencyCompany.setCreateDate(new Date());
        agencyCompany.setUpdateDate(new Date());
        agencyCompanyMapper.insert(agencyCompany);
    }
    /**
     * @name  修改代理公司
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public void AgencyCompanyupdate(AgencyCompany agencyCompany) {
        agencyCompany.setUpdateDate(new Date());
        agencyCompanyMapper.updateByPrimaryKey(agencyCompany);
    }
    /**
     * @name  id查询
     * @Author VULCAN
     * @Date 2020/2/1 12:36
     */
    @Override
    public AgencyCompany AgencyCompanyFindId(String id) {
        return agencyCompanyMapper.selectByPrimaryKey(id);
    }
    /**
      * @name  分页 模糊
     * @Author VULCAN
     * @Date 2020/2/1 12:57
     */
    @Override
    public PageResult findAgencyCompanylikename(AgencyCompany agencyCompany, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<AgencyCompany> findagencyCompany = (Page<AgencyCompany>) agencyCompanyMapper.findAgencyCompanylikename(agencyCompany);
        return new PageResult(findagencyCompany.getTotal(),findagencyCompany.getResult());
    }
    /**
     * @name  批量删除
     * @Author VULCAN
     * @Date 2020/2/1 15:12
     */
    @Override
    public String agencyCompanybulkdel(String[] ids) {
        for (String id : ids) {
            agencyCompanyMapper.deleteByPrimaryKey(id+"");
            coverOrderMapper.deleteByPrimaryKeycoverId(id+"");
        }
        return null;
    }
    /**
     * @name  套信息 分页 模糊
     * @Author VULCAN
     * @Date 2020/2/1 12:54
     */
    @Override
    public PageResult findcoverlikename(Cover covers, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<Cover> findcovers = (Page<Cover>) coversMapper.findcoverlikename(covers);
        return new PageResult(findcovers.getTotal(),findcovers.getResult());
    }
    /**
     * @name  新增套信息
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public void coveradd(Cover covers) {

        covers.setId(idWorker.nextId()+"");
        covers.setCreateDate(new Date());
        covers.setUpdateDate(new Date());
        String nextId = idWorker.nextId()+"";
        covers.setClassid(nextId.substring(16));
        coversMapper.insert(covers);
        System.out.println(covers.getId());
        redisTemplate.opsForValue().set("coversId",covers.getId());
    }
    /**
     * @name  修改套信息
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public void coverupdate(Cover covers) {
        coverSnapshotMapper.deleteByPrimaryKey(covers.getId());
        covers.setUpdateDate(new Date());
        coversMapper.updateByPrimaryKey(covers);
    }
    /**
     * @name  id查询
     * @Author VULCAN
     * @Date 2020/2/1 12:36
     */
    @Override
    public Cover coverFindId(String id) {
        return coversMapper.selectByPrimaryKey(id);
    }
    /**
     * @name  套信息批量删除
     * @Author VULCAN
     * @Date 2020/2/1 15:12
     */
    @Override
    public String coversbulkdel(String[] ids) {
        for (String id : ids) {
            coversMapper.deleteByPrimaryKey(id+"");
        }
        return null;
    }

    /**
     * @name  整合模糊
     * @Author VULCAN
     * @Date 2020/2/1 12:53
     */
    @Override
    public PageResult findcoverVolikename(CoverVo CoverVo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CoverVo> findCoverVo = (Page<CoverVo>) coverVoMapper.findcoverVolikename(CoverVo);
        return new PageResult(findCoverVo.getTotal(),findCoverVo.getResult());
    }
    /**
     * @name  id查询
     * @Author VULCAN
     * @Date 2020/2/1 12:38
     */
    @Override
    public CoverOrder selectByPrimaryKey(String id) {
        return coverOrderMapper.selectByPrimaryKeycoverId(id);
    }
    /**
     * @name  新增套订单信息
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public void coverOrderadd(CoverOrder coverOrder) {
        coverOrder.setOrderId(idWorker.nextId()+"");
        String coversId = (String) redisTemplate.opsForValue().get("coversId");
        System.out.println(coversId);
        coverOrder.setCoverId(coversId);
        coverOrder.setReviewType("1");
        coverOrder.setContiunedStatus("0");
        coverOrder.setAogeMoney(0.0);
        coverOrder.setOrderPay(0.0);
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        String format1 =  format.format(new Date());
        coverOrder.setOrderYear(format1);
        coverOrder.setOrderType("1");  //新增
//        Cover cover = coversMapper.selectByPrimaryKey(coversId);
//        String coverName = cover.getCoverName();
        String nextId = idWorker.nextId()+"";

        coverOrder.setOrderCoverNumber(SystemIDUtil.getOCJ()+nextId.substring(0,2));
        coverOrderMapper.insert(coverOrder);
        redisTemplate.delete("coversId");
    }
    /**
     * @name  修改套订单信息
     * @Author VULCAN
     * @Date 2020/2/1 11:50
     */
    @Override
    public void coverOrderupdate(CoverOrder coverOrder) {
        coverOrder.setReviewType("0");
        coverOrderMapper.updateByPrimaryKey(coverOrder);
    }
    /**
     * @name  套信息批量审核
     * @Author VULCAN
     * @Date 2020/2/1 15:12
     */
    @Override
    public String coversbulkaudit(String[] ids) {
        for (String id : ids) {
            CoverOrder coverOrder = coverOrderMapper.selectByPrimaryKeycoverId(id + "");
            coverOrder.setReviewType("1");
            coverOrderMapper.updateaudit(coverOrder);
        }
        return null;
    }
    /**
     * @name  整合模糊 审核
     * @Author VULCAN
     * @Date 2020/2/1 12:53
     */
    @Override
    public PageResult findcoverVoauditlikename(CoverVo coverVo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CoverVo> findCoverVoaudit = (Page<CoverVo>) coverVoMapper.findcoverVoauditlikename(coverVo);
        return new PageResult(findCoverVoaudit.getTotal(),findCoverVoaudit.getResult());
    }
    /**
     * @name  套信息批量审核 通过
     * @Author VULCAN
     * @Date 2020/2/1 15:12
     */
    @Override
    public String coversbulkauditpass(String[] ids) {
        for (String id : ids) {
            CoverOrder coverOrder = coverOrderMapper.selectByPrimaryKeycoverId(id + "");
            coverOrder.setReviewType("2");
            coverOrderMapper.updateaudit(coverOrder);
        }
        return null;
    }
    /**
     * @name  套信息批量审核 驳回
     * @Author VULCAN
     * @Date 2020/2/1 15:12
     */
    @Override
    public String coversbulkauditturn(String[] ids) {
        for (String id : ids) {
            CoverOrder coverOrder = coverOrderMapper.selectByPrimaryKeycoverId(id + "");
            coverOrder.setReviewType("0");
            coverOrderMapper.updateaudit(coverOrder);
        }
        return null;
    }
    /**
     * @name  整合模糊  订单
     * @Author VULCAN
     * @Date 2020/2/1 12:38
     */
    @Override
    public PageResult findcoverVoauditpasslikename(CoverVo coverVo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CoverVo> findCoverVoauditpass = (Page<CoverVo>) coverVoMapper.findcoverVoauditpasslikename(coverVo);
        return new PageResult(findCoverVoauditpass.getTotal(),findCoverVoauditpass.getResult());
    }
//    /**
//     * @name  查询订单
//     * @Author VULCAN
//     * @Date 2020/2/3 15:57
//     */
//    @Override
//    public List<Orders> findbyorder() {
//        return ordersMapper.findbyorderList();
//    }
//    /**
//     * @name  订购类型统计
//     * @Author VULCAN
//     * @Date 2020/2/3 19:27
//     */
//    @Override
//    public List<Orders> findbyordertype() {
//        return ordersMapper.findbyordertype();
//    }
//    /**
//     * @name  是否到货统计
//     * @Author VULCAN
//     * @Date 2020/2/3 19:27
//     */
//    @Override
//    public List<Orders> findbyorderarrival() {
//        return ordersMapper.findbyorderarrival();
//    }
    /**
     * @name  荐购学科统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchasesubjectTj() {
        return purchaseMapper.selectPuchasesubjectTj();
    }
    /**
     * @name  荐购国家统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchasecountryTj() {
        return purchaseMapper.selectPuchasecountryTj();
    }
    /**
     * @name  荐购语种统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchaselanguageTj() {
        return purchaseMapper.selectPuchaselanguageTj();
    }
    /**
     * @name  荐购文献统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchasetypeTj() {
        return purchaseMapper.selectPuchasetypeTj();
    }
    /**
     * @name  荐购币种统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchasecurrencyTj() {
        return purchaseMapper.selectPuchasecurrencyTj();
    }
    /**
     * @name  荐购出版状态统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchasepub_statusTj() {
        return purchaseMapper.selectPuchasepub_statusTj();
    }
    /**
     * @name  荐购载体统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectPuchasecarrierTj() {
        return purchaseMapper.selectPuchasecarrierTj();
    }
    /**
     * @name  套信息列表
     * @Author VULCAN
     * @Date 2020/2/5 11:30
     */
    @Override
    public List<Cover> CoverFindlist() {
        return coversMapper.selectByExample(null);
    }
    /**
     * @name  套学科统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectcoversubjectTj() {
        return coversMapper.selectcoversubjectTj();
    }
    /**
     * @name  套国家统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectcovercountryTj() {
        return coversMapper.selectcovercountryTj();
    }
    /**
     * @name  套语种统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectcoverlanguageTj() {
        return coversMapper.selectcoverlanguageTj();
    }
    /**
     * @name  套文献统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectcovertypeTj() {
        return coversMapper.selectcovertypeTj();
    }
    /**
     * @name  套载体统计
     * @Author VULCAN
     * @Date 2020/2/4 16:08
     */
    @Override
    public List<Purchase> selectcovercarrierTj() {
        return coversMapper.selectcovercarrierTj();
    }
    /**
     * @name  id查询
     * @Author VULCAN
     * @Date 2020/2/7 14:30
     */
    @Override
    public List<CoverVo> findcoverVofindById(String id) {
        return coverVoMapper.findcoverVofindById(id);
    }
    /**
     * @name  查询套订单信息
     * @Author VULCAN
     * @Date 2020/2/7 15:51
     */
    @Override
    public List<CoverOrder> selectBycoverId(String coverId) {
        return coverOrderMapper.selectBycoverId(coverId);
    }
    /**
     * @name  查询套信息快照
     * @Author VULCAN
     * @Date 2020/2/8 10:01
     */
    @Override
    public CoverSnapshot selectByCoverSnapshot(String id) {
        return coverSnapshotMapper.selectByPrimaryKey(id);
    }
    /**
     * @name  查询套信息快照添加
     * @Author VULCAN
     * @Date 2020/2/8 10:01
     */
    @Override
    public void addCoverSnapshot(CoverSnapshot coverSnapshot) {
        coverSnapshotMapper.deleteByPrimaryKey(coverSnapshot.getId());
        coverSnapshotMapper.insert(coverSnapshot);
    }
    /**
     * @name  id查询套信息快照
     * @Author VULCAN
     * @Date 2020/2/9 17:32
     */
    @Override
    public CoverVo findcoversnapshotfindById(String id) {
        return coverVoMapper.findcoversnapshotfindById(id);
    }
    /**
     * @name  id查询套信息
     * @Author VULCAN
     * @Date 2020/2/9 17:32
     */
    @Override
    public CoverVo findcoverfindById(String id) {
        return coverVoMapper.findcoverfindById(id);
    }

}
